//
//  ViewController.swift
//  PushExten
//
//  Created by zz on 20.3.24.
//

import UIKit

class ViewController: UIViewController {
    
    let semaphore = DispatchSemaphore(value: 1)
    let queue = DispatchQueue(label: "com.example.serialQueue")
    
    
    var isSound:Bool = false
    
    override func viewDidLoad() {
        super.viewDidLoad()
        print("Do any additional setup after loading the view.")
//        [[NSNotificationCenter defaultCenter] addObserver:self
//                                                     selector:@selector(writefile)
//                                                         name:UIApplicationDidEnterBackgroundNotification
//                                                       object:nil];
        NotificationCenter.default.addObserver(self,
                                               selector: #selector(writefile),
                                               name: UIApplication.didEnterBackgroundNotification,
                                               object: nil)

    }
    
    @objc func  writefile() {
        
    }
    
    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        

        let monery = ApnsHelper.shared.getMusicArray(with: "168.07")
//        let name = ApnsHelper.shared.mergeVoice(musicArry: monery)
//        playVoice(source: source, topIndex: 0) {[weak self] in
//            self?.isSound = false
//        }
        
        let path = Bundle.main.path(forResource: "1.mp3", ofType: nil)!
        let path2 = Bundle.main.path(forResource: "2.mp3", ofType: nil)!
        let path3 = Bundle.main.path(forResource: "user_payment.mp3", ofType: nil)!
//        ApnsHelper.shared.mergeAVAsset(with: [path3,path,path2]) { path in
//            
//        }
        
        ApnsHelper.shared.mergeVoiceAudiFileName(musicArry: monery) { audioFileName in
            print("===========\(audioFileName)")
        }
        
        
    }
    
    func playVoice(source:[[String]],topIndex:Int,complete:(()->Void)?) {
        
//        if !self.isSound {
//            self.isSound = true
//            var index = topIndex
//            if index < source.count {
//                let voiceItem = source[index]
//                index = index + 1
//                ApnsHelper.shared.playVoice(musicArray: voiceItem, topIndex: 0) {[weak self] in
//                    self?.playVoice(source: source, topIndex: index,complete: complete)
//                }
//            }else {
//                complete?()
//            }
//        }
       
        
    }
    
    lazy var source: [[String]] = {
        let source = [[String]]()
        return source
    }()
    
    
}

